# Maintainer: David Runge <dvzrv@archlinux.org>

pkgname=molecule
pkgver=5.0.0
pkgrel=2
pkgdesc="Aids in the development and testing of Ansible roles"
arch=(any)
url="https://github.com/ansible-community/molecule"
license=(MIT)
depends=(
  python
  python-ansible-compat
  python-click
  python-click-help-colors
  python-cookiecutter
  python-enrich
  python-jinja
  python-jsonschema
  python-packaging
  python-pluggy
  python-pyyaml
  python-rich
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-setuptools-scm
  python-wheel
)
checkdepends=(
  ansible
  check-jsonschema
  python-ansi2html
  python-filelock
  python-pexpect
  python-pytest
  python-pytest-mock
  python-pytest-testinfra
  python-pytest-xdist
  yamllint
)
optdepends=(
  'ansible: for the ansible verifier'
  'molecule-docker: for the docker driver'
  'molecule-podman: for the podman driver'
  'molecule-vagrant: for the vagrant driver'
  'python-pywinrm: for Windows support'
  'python-pytest-testinfra: for the testinfra verifier'
)
source=(https://files.pythonhosted.org/packages/source/${pkgname::1}/$pkgname/$pkgname-$pkgver.tar.gz)
sha512sums=('aa25a0f945c69ab18844ff83d26071849c01d9ee8acf654a64d8c2d5a74140322d94e20f5b7843865f78ab77843d4a34a2a83b611ec1a5b479f753e9f53fdeb9')
b2sums=('3b9b8fdb807381fbec752b27b5ae85d370953df2e17ddf6e4d166f6116b622b859cdd2eb3058e64fec569856ef884002880c0762ab2e8e94463c654d86edbcd8')

prepare() {
  # fix YOLO ansible-compat change: https://github.com/ansible-community/molecule/issues/3903
  sed -e 's/runtime.exec/runtime.run/' -i $pkgname-$pkgver/src/$pkgname/util.py
}

build() {
  cd $pkgname-$pkgver
  python -m build --wheel --skip-dependency-check --no-isolation
}

check() {
  local site_packages=$(python -c "import site; print(site.getsitepackages()[0])")
  cd $pkgname-$pkgver

  # install into test location
  python -m installer --destdir=test_dir dist/*.whl
  export PYTHONPATH="test_dir/$site_packages:$PYTHONPATH"
  export PATH="test_dir/usr/bin:$PATH"
  pytest -v "test_dir/$site_packages/molecule/test/unit/" -c /dev/null
}

package() {
  cd $pkgname-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
}
